import java.util.Scanner;

public class towork7  {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] matrix = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                matrix[i][j] = sc.nextInt();
            }
        }
        int ans = Integer.MIN_VALUE;
        for (int x1 = 0; x1 < n; x1++) {
            for (int y1 = 0; y1 < m; y1++) {
                for (int len = 1; x1 + len < n && y1 + len < m; len++) {
                    int x2 = x1 + len;
                    int y2 = y1 + len;
                    int tmp = 0;
                    for (int y = y1; y <= y2; y++) {//上
                        tmp += matrix[x1][y];
                    }
                    for (int y = y1; y <= y2; y++) {//下
                        tmp += matrix[x2][y];
                    }

                    for (int x = x1 + 1; x < x2; x++) {//左
                        tmp += matrix[x][y1];
                    }
                    for (int x = x1 + 1; x < x2; x++) {//右
                        tmp += matrix[x][y2];
                    }
                    ans = Math.max(ans, tmp);
                }
            }
        }
        System.out.println(ans);
    }


}